//           Copyright Joe Coder 2004 - 2006.
//  Distributed under the Boost Software License, Version 1.0.
//     (See accompanying file LICENSE_1_0.txt or copy at
//           http://www.boost.org/LICENSE_1_0.txt)

#include <iostream>
#include "eipp.h"
#include "eipp_packet.h"

using namespace eipp;
using namespace std;

int main()
{
	while(1)
	{
		atom_t cmd; // atom type... think std::string
		et data;    // generic "erlang term" type

		// expect tuple of the form {CmdAtom, Data}
		untuple(cmd,data)=binary_to_term(receive4(cin));
		
		// Only one command supported for now...
		if(cmd=="times2")
		{
			int num=data; // "et" can cast itself to many types
			num*=2;
			send4(cout,term_to_binary(tuple("ok",num)));
		}
	}
}
